home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / AppleTalk Wide Area / XTI Shell Sample Code / XTIShell.a next >
Encoding:
Text File  |  1993-02-15  |  22.6 KB  |  718 lines  |  [TEXT/MPS ]

  1. ;_________________________________________________________________________________
  2. ;
  3. ;    File:        XTIShell.a
  4. ;    
  5. ;    This file contains code that implements calls from AURP to the adev.  Once 
  6. ;    the call is determined, a routine in C is usually called to perform the guts 
  7. ;    of the call (with a few exceptions).  These C routines can be found in XTIShell.c.
  8. ;    Hints on things that may need to be change are provided throughtout.
  9. ;
  10. ;    Apple Computer, Inc. 
  11. ;    Copyright (C) 1992,1993.  All rights reserved.
  12. ;    
  13. ;    Revision History:
  14. ;    
  15. ;__________________________________________________________________________________
  16.             
  17.             PRINT        PUSH,OFF
  18.             INCLUDE       'SysEqu.a'                         ; System definitions
  19.             INCLUDE       'SysErr.a'                         ; System errors
  20.             INCLUDE       'ToolEqu.a'                     ; Toolbox definitions
  21.             INCLUDE        'Traps.a'                        ; Traps definitions
  22.             INCLUDE        'LAPEqu.a'                        ; LAP manager defs
  23.             INCLUDE        'AURPEqu.a'                        ; AURP atlk definitions
  24.             INCLUDE        'HardwareEqu.a'                    ; some hardware stuff
  25.             INCLUDE       'Private.a'                     ; System private definitions
  26.             PRINT        POP
  27.             
  28.             EXPORT        GETSYSMEM, GETMYA5, SETMYA5
  29.             
  30. ;
  31. ; The main shell structure.  Modify if necessary, but the variables
  32. ; provided should be sufficient.
  33. ;
  34. XTIvarsRec        RECORD        0                            ; MIRROR XTISHELL.H
  35. cGlobals        DS.L        1                            ; Ptr to variables used in C routine
  36. HopCntWght        DS.W        1                            ; ipt's hop count weight
  37. remoteAddr        DS.B        16                            ; remote DTE address as pascal string
  38. AURPWriteEntry    DS.L        1                            ; AURP LAP write code entry point
  39. AURPRefNum        DS.L        1                            ; AURP refnum
  40. NextIRBlk         DS.L        1                            ; next IR
  41. lineSpeed         DS.L        1                            ; faked line speed to tell the router
  42. AURPDispatch    DS.L        1                            ; aurp dispatch routine
  43. OurDI            DS.W        1                            ; our domain identifier
  44. otherNode        DS.L        1                            ; domain identifier
  45. maxRPktSz        DS.W        1                            ; maximum packet size
  46. wDSPtr            DS.L        1                            ; WDSPtr for XTIWRITE
  47. rcvBufAvail        DS.B        1                            ; set flag if receive buffer is available
  48. rcvPktsWaiting    DS.B        1                            ; flag will be set in C routine if data are outstanding
  49. XTIFlags        DS.B        1                            ; flags for this atlk
  50. OurPortId        DS.B        1                            ; Our port id
  51. OurSlotId        DS.B        1                            ; Our slot id , will be set in C routine
  52. XTIvarsize        DS.B        0
  53.                 ENDR
  54.  
  55. LWEnableSCC    EQU    6        ; Don't disable SCC
  56.  
  57. ; XTIFlags bits
  58. XTIInit            EQU        0                                    ; bit 0, set if init'ed
  59. XTIClose        EQU        1                                    ; bit 1, set if closing
  60. XTILapInst        EQU        2                                    ; bit 2, set if LAP write code is installed
  61.  
  62.  
  63. ;________________________________________________
  64. ;
  65. ;    Begin main atlk code
  66. ;
  67. ;________________________________________________
  68.  
  69. XTISHELL    MAIN        EXPORT                            ; this entry point is the LAPWRITE hook
  70.  
  71.             IMPORT        DOXTIINSTALL, DOXTIDISCONNECT, DOXTISHUTDOWN, XTICONNECT, XTIWRITE, READDONE
  72.             EXPORT        CONNDONE, GETGLOBALS
  73.  
  74.             WITH         XTIVarsRec
  75. ;
  76. ;    If the code is entered at this point, the LAP Manager is calling the adev
  77. ;    to perform a write, so just branch to the LAPWrite code.
  78. ;
  79.             BRA.S        LAPWrite
  80. ;
  81. ;    AURP is calling us.  On entry D0 contains command code.  Use the jump tables
  82. ;    (ControlTable and XTICntrlTbl) to jump to appropriate routine.  ControlTable 
  83. ;    has a base of D0 = 0, and XTICntrlTbl has a base of D0 = 32.  This code should
  84. ;    NOT need any modifications.
  85. ;
  86. XTIControl    
  87.             LINK        A6,#0                            ; allocate our local stack frame
  88.             MOVEM.L        A2-A3/D3-D4,-(SP)                ; save these registers
  89.                                                         ; for all control calls.
  90.             CMP.W        #AInstall,D0                    ; is it an install call?
  91.             BNE.S        @tryAGetIF                        ; branch if not
  92. @ProcReq
  93.             MOVE.L        D1,-(SP)                        ; save this reg.
  94.             ADD.W        D0,D0                            ; D0 = D0 * 2;
  95.             MOVE.W        ControlTable(D0.W),D0            ; get the routine offset
  96.             JSR            ControlTable(D0.W)                ; process the request
  97.             BRA.S        @XTICntrlDone
  98. @tryAGetIF
  99.             MOVE.L        ATLKVars,A3                        ; A3 -> our variables
  100.             CMP.W        #AGetInfo,D0                    ; is it a get info call?
  101.             BEQ.S        @ProcReq                        ; branch if so
  102. @tryShutDwn            
  103.             CMP.W        #AShutdown,D0                    ; is it a shutdown call?
  104.             BEQ.S        @ProcReq                        ; branch if so
  105.             
  106.             CMP.W        #ATnlGetNextIR,D0                ; is it a NextIR req call?
  107.             BEQ.S        @ProcReq2                        ; branch if so
  108.             
  109.             CMP.W        #ATnlDisconnect,D0                ; is it a disconnect req call?
  110.             BEQ.S        @ProcReq2                        ; branch if so
  111.  
  112.             CMP.W        #ATnlConnect,D0                    ; is it a connect call?
  113.             BNE.S        @ParamError                        ; branch if not
  114. @ProcReq2
  115.             MOVE.L        D1,-(SP)                        ; save this reg.
  116.             SUB.W        #ATnlConnect,D0                    ; adjust call # for 2nd tbl            
  117.             ADD.W        D0,D0                            ; D0 = D0 * 2;
  118.             MOVE.W        XTICntrlTbl(D0.W),D0                ; get the routine offset
  119.             JSR            XTICntrlTbl(D0.W)                ; process the request
  120. @XTICntrlDone
  121.             MOVE.L        (SP)+,D1                        ; restore this one
  122.             MOVEM.L        (SP)+,A2-A3/D3-D4
  123.             UNLK        A6
  124.             RTS
  125. @ParamError
  126.             MOVEM.L        (SP)+,A2-A3/D3-D4
  127.             BSR.S        ParamError                        
  128.             UNLK        A6
  129.             RTS            
  130.  
  131. ;
  132. ;    The LAP Manager wants us to write out a packet.
  133. ;    Give it to AURP.
  134. ;
  135. LAPWrite:
  136.              CMP.B        #0,D0                            ; Write pkt out?
  137.  
  138.             MOVE.L        ATLKvars, A3
  139.             MOVE.L        XTIVarsRec.AURPRefNum(A3), D1
  140.             MOVE.L        XTIVarsRec.AURPWriteEntry(A3), A3
  141.             JMP            (A3)
  142.             
  143. ;
  144. ;    The control table for standard atlk calls made from AURP
  145. ;
  146. ControlTable
  147.             DC.W        ParamError-ControlTable            ; D0 = 0 not supported
  148.             DC.W        DoInstall-ControlTable            ; D0 = 1 AInstall Lap     
  149.             DC.W        DoShutdownAtlk-ControlTable        ; D0 = 2 AShutdown Lap
  150.             DC.W        DoGetInfo-ControlTable            ; D0 = 3 AGetInfo
  151.  
  152. ;
  153. ;    The control table for AURP specific atlk calls made from AURP
  154. ;    Note: D0 base is 32.
  155. ;
  156. XTICntrlTbl
  157.             DC.W        DoATlkConnect-XTICntrlTbl        ; D0 = 0 ATnlConnect
  158.             DC.W        DoATnlDisconnect-XTICntrlTbl    ; D0 = 1 ATnlDisconnect pkt
  159.             DC.W        GetNextIR-XTICntrlTbl            ; D0 = 2 return next ir
  160.  
  161. ParamError    
  162.             MOVEQ.L        #-1,D0                            ; Indicate failure
  163.             RTS
  164.     
  165. ;
  166. ;     XTIShellVarsPtr GETGLOBALS (void)
  167. ;
  168. GetGlobals
  169.             MOVE.L        ATLKvars,D0
  170.             RTS
  171.             
  172. ATLKvars    DC.L        0                                ; a pointer to our vars
  173.             UNLK        A6
  174.             RTS
  175.  
  176.             
  177. ;________________________________________________
  178. ;
  179. ;    DoInstall
  180. ;
  181. ;    This code performs the installation of the adev (AURP AInstall).
  182. ;    Possible modifications to be made are the Domain Indicator and
  183. ;    NextIRBlock returned to AURP, but should not be necessary except
  184. ;    for point to point links.
  185. ;    
  186. ;     Call:     
  187. ;        D3.L     =    AURP LAP write code entry point
  188. ;        D4.L    =    port number on which to perform the install operation
  189. ;        A0.L     ->     AURP Interface Dispatch Routine
  190. ;        A1        ->    pointer to ATnlConfig parameter block
  191. ;        A2        =   AURP Refnum
  192. ;
  193. ;    Return:     
  194. ;        D0.W     =    error code (non zero indicates an error)
  195. ;        A1        ->    pointer to ATnlConfig parameter block
  196. ;
  197. ;________________________________________________
  198.  
  199. InstallErr
  200.             MOVEM.L        (SP)+,A0-A1                        ; clean up stack
  201.             BRA            CloseADEV                        ; and close
  202. Install2Err
  203.             MOVE.L        ATLKvars, A0                    
  204.             _DisposPtr                                    ; dispose of the ATLKvars
  205.             MOVEM.L        (SP)+, A0-A1                    ; clean up stack
  206.             BRA            CloseADEV                        ; and close
  207. Install3Err
  208.             MOVE.L        ATLKvars, A0                
  209.             _DisposPtr                                    ; dispose of the ATLKvars
  210.             MOVE.L        NextIRBlk(A3), A0
  211.             _DisposPtr                                    ; dispose of the NextIRBlk
  212.             MOVEM.L        (SP)+, A0-A1                    ; clean up stack
  213.             BRA            CloseADEV                        ; and close
  214.  
  215. DoInstall                                                ; initialization
  216.              
  217.             MOVEM.L        A0-A1,-(SP)                        ; save off rtmi ptr and port info pb        
  218.             MOVE.L        #XTIvarsize,D0                    ; size of our vars
  219.             _NewPtr        ,SYS,CLEAR                        ; get some memory
  220.             BNE.S        InstallErr                        ; no can do
  221.             LEA            ATLKvars,A3
  222.             MOVE.L        A0,(A3)                            ; save vars ptr
  223.             MOVE.L        A0,A3                            ; A3-> our vars
  224.             MOVE.L        D3, AURPWriteEntry(A3)            ; save the write entry code pointer
  225.             MOVE.L        A2, AURPRefNum(A3)                ; save the AURP vars
  226.             MOVE.L        #6, D0
  227.             _NewPtr        ,SYS,CLEAR                        ; get some memory
  228.             BNE.S        Install2Err
  229.             MOVE.L        A0, XTIVarsRec.NextIRBlk(A3)    ; save the next IR blk value
  230.             MOVE.B        D4,OurPortId(A3)                ; save our port number
  231.                                             
  232.             MOVEM.L        (SP),A0-A1                        ; restore A0 & A1 = port info pb
  233.             MOVE.L        A1, A2                            ; move the port info pointer into A2
  234.             MOVE.L        A0,AURPDispatch(A3)                ; save aurp dispatch routine
  235.             MOVE.W        ATnlCfgPBlk.HopCntWgt(A2),D0    ; save hopcount weight
  236.             MOVE.W        D0, HopCntWght(A3)
  237.             MOVE.L        ATnlCfgPBlk.PaidPtr(A2),A0        ; A0 -> paid ptr (src ptr)
  238.             ADDQ.L        #2, A0                            ; skip length
  239.             MOVE.L        A0, -(SP)                        ; move paid ptr onto stack
  240.             MOVE.L        ATnlCfgPBlk.ACfgPtr(A2),A0        ; A0 -> acfg ptr (src ptr)
  241.             MOVE.L        A0, -(SP)                        ; move acfg ptr onto stack
  242.             MOVE.L        A3, -(SP)                        ; move varsPtr onto stack
  243.             JSR            DOXTIINSTALL                    ; call C routine 
  244.             ADDA        #12, SP
  245.             TST.W        D0            
  246.             BNE.S        Install3Err                        ; no can do
  247.             
  248.             MOVEM.L        (SP)+,A0-A1                        ; restore A0 & A1 = port info pb
  249.             MOVE.L        A1, A2                            ; move the port info pointer into A2
  250. ;        
  251. ; Insert atlk's LAP write code
  252. ;
  253. @InsertLW    MOVEA.L        LAPMgrPtr,A1                    ; A1->LAPmgr
  254.             MOVEQ        #LWrtInsert,D0                    ; func code
  255.             LEA            XTISHELL,A0                        ; A0->us
  256.             CLR.B        D1
  257.             CLR.W        D2                                ; try ENQ's forever maybe
  258.             BSET        #LWEnableSCC,D1                    ; don't disable SCC when calling us
  259.             JSR            LAPMgrCall(A1)                    ; install ourself as new LAPWrite
  260.             BSET        #XTILapInst, XTIFlags(A3)        ; set flag that LAP write code is installed
  261.                     
  262. ;
  263. ; Setup the ATnlPBlk entries to give to AURP
  264. ; A2 still equals the pointer to ATnlConfigPB
  265. ;
  266.             MOVE.L        #0, D2
  267.             MOVE.W        maxRPktSz(A3), D2                    ; D2 = max packet size
  268.              MOVE.W        D2, ATnlCfgPBlk.maxRPktSz(A2)        ; D2 needs to be size of Packet
  269.              MOVEQ        #0, D1                                ; D1 = kRtr flags
  270.              BSET.L        #ConfigLstOnly, D1                    ; use only our list of one
  271.             MOVE.L        D1, ATnlCfgPBlk.atlkFlags(A2)        ; set up the router host flags
  272.              LEA            DoXTIWrite, A0
  273.             MOVE.L        A0, ATnlCfgPBlk.atlkWriteCode(A2)    ; setup the write code
  274.             LEA            FreeReadBuf, A0
  275.             MOVE.L        A0, ATnlCfgPBlk.atlkReadDone(A2)    ; setup the read done code
  276.             MOVE.W        #1, ATnlCfgPBlk.numNextIRs(A2)        ; setup num next IRs
  277.             MOVE.B        #1, ATnlCfgPBlk.srcDILen(A2)        ; set up our srcDI length
  278. ;
  279. ; The domain indicator for a point to point link is set to 1.  This indicator
  280. ; is more relevant for multipoint links for routers to distinguish who the
  281. ; information is coming from.  On point to point links, there is only one other
  282. ; router the data could be coming from.
  283. ;
  284.             LEA            XTIVarsRec.OurDI(A3), A1            ; save ourDI
  285.             MOVE.W        #$0100, (A1)                        ; this is the null DI
  286. ;
  287. ; The otherNode variable is set in XTIShell.c to a value indicating that
  288. ; the other (next) router (in this case the other end of the point to point
  289. ; link) is answering or calling.  This information is used in a multipoint link
  290. ; when AURP indicates a write is to be made to know which router to write to.
  291. ; However, with a point to point link, there is only one router to write to,
  292. ; making nextIR irrelevant.
  293. ;
  294.             MOVE.L        XTIVarsRec.NextIRBlk(A3),A0            ; get the next IR blk value
  295.             MOVE.W        #1, (A0)                            ; save length = 1
  296.             MOVE.L        otherNode(A3), 2(A0)                ; save other nir
  297.             MOVE.L        A0, -(SP)                            ; next ir block ptr
  298.  
  299.             PEA            XTIVarsRec.OurDI(A3)                ; our address
  300.             MOVE.L        XTIVarsRec.AURPRefNum(A3), -(SP)    ; the aurp vars
  301.             MOVE.L        #kAURPInstallDone, -(SP)            ; csCode = AURPInstallDone
  302.             MOVE.L        XTIVarsRec.AURPDispatch(A3), A0        ; the dispatch rtn
  303.             JSR            (A0)                                ; call it
  304.             ADDA        #16, SP                                ; 
  305.             CLR.W        D0                                    ; set return code for caller
  306.             RTS
  307.                 
  308. ;________________________________________________
  309. ;
  310. ;    DoGetInfo
  311. ;
  312. ;    This code performs the AURP AGetInfo call to get information
  313. ;    about the adev.  Possible modification would be to the link
  314. ;    address (probably not).  Since most of the variables are set
  315. ;    in the C routines, this code is probably ok.
  316. ;
  317. ; Call:         
  318. ;            D1.W    =    length of reply buffer
  319. ;            A1.L    ->    reply buffer
  320. ;             
  321. ;
  322. ; Return:    A1.L    ->    reply buffer
  323. ;            D0.W    =   Result code
  324. ;________________________________________________
  325.             
  326.             WITH        ATlkInfo
  327.  
  328. DoGetInfo:
  329.             CMP.W        #AInfoSz,D1                        ; buffer big enough?
  330.             BLT.S        @Error                            ; no
  331.  
  332.             MOVE.L        ATLKvars,D3                        ; has this atlk been installed?
  333.             BEQ.S        @Error                            ; no
  334.             
  335.             MOVE.L        D3,A3                            ; A3 -> our vars
  336.             MOVE.L        A1,A2                            ; 
  337.             MOVE.W        #AInfoVers,Version(A2)            ; version (of atlk)
  338.             MOVE.W        #AInfoSz,InfoLength(A2)            ; number of bytes returned
  339.  
  340.             BTST.B        #XTIInit, XTIFlags(A3)            ; see if we've inited
  341.             BNE.S        @initInfo                        ; if so, give real values
  342.             MOVE.L        lineSpeed(A3),LinkSpeed(A2)        ; the line speed 
  343.             CLR.B        BandWidth(A2)                    ; bandwidth (weight factor)
  344.             BRA.S        @contInfo
  345.  
  346. @initInfo    MOVE.B        HopCntWght+1(A3),Bandwidth(A2)    ; link weight (value returned from AURP + 1)
  347. @contInfo    CLR.B        Reserved(A2)                    ; reserved (must be zero)
  348.             CLR.W        Reserved+1(A2)
  349.             MOVE.B        OurSlotId(A3), Reserved+1(A2)    ; "slot number" in second reserved byte for SNMP
  350.             MOVEQ        #0,D0                            ; flags
  351.             BSET        #AtlkExtended,D0                ; extended port
  352.             MOVE.B        D0,Flags(A2)
  353.  
  354.             MOVE.B        #0,LinkAdrLen(A2)                ; no relevant addr
  355.             
  356.             MOVEQ        #noErr,D0
  357.             RTS                                            ; return success
  358. @Error
  359.             MOVEQ        #-1,D0                            ; return error
  360.             RTS
  361. ;________________________________________________
  362. ;
  363. ;    DoAtlkConnect
  364. ;
  365. ;    This code performs the AURP ATnlConnect call.  The guts of the call
  366. ;    are performed in the C routine XTICONNECT.  Should NOT need to be
  367. ;    modified.
  368. ;
  369. ; No parameters sent in.
  370. ;
  371. ; Return:    D0.W    =   Result code
  372. ;________________________________________________
  373.  
  374. DoAtlkConnect
  375.             MOVE.L        ATLKvars, A3
  376.             BCLR        #XTIClose, XTIFlags(A3)            ; connection no longer closed
  377.             MOVE.L        A3, -(SP)                        ; pass our vars
  378.             JSR         XTICONNECT                        ; call C routine to start connection
  379.             ADDQ.L        #4,SP                            ; restore stack
  380.             TST.W        D0
  381.             BNE            CloseADEV
  382.             
  383.  
  384.             RTS
  385. ;__________________________________________
  386. ;
  387. ;     ConnDone (long errResult);
  388. ;
  389. ;     This routine is called from several C routines to indicate that
  390. ;     a connection is complete, a connection could not be established,
  391. ;    or a connection has gone down unexpectedly.  AURPTnlConnDone is 
  392. ;    called with noErr or with an error (latter two cases).  If it is
  393. ;    called with an error, the port will be made inactive.  Should
  394. ;    NOT need to be modified.
  395. ;
  396. ;__________________________________________
  397.  
  398. CONNDONE
  399.             MOVE.L        A3, -(SP)                        ; save A3
  400.             MOVE.L        ATLKvars, A3                    ; get our vars
  401.             MOVE.L        8(A7), D0                        ; see if connection good
  402.             BNE.S        @ConnErr                        ; if not, error
  403.             BSET        #XTIInit, XTIFlags(A3)            ; set flag that init done
  404.  
  405.             MOVE.L        #0, -(SP)                        ; the connection result
  406.             MOVE.L        AURPRefNum(A3), -(SP)            ; pass the vars
  407.             MOVE.L        #kAURPTnlConnDone, -(SP)        ; cmdType = TnlConnection Done
  408.             MOVE.L        AURPDispatch(A3), A3             ;
  409.             JSR            (A3)                            ; make the call
  410.             ADDA        #12, SP
  411.             MOVE.L        (SP)+, A3
  412.             RTS
  413.             
  414. @ConnErr    MOVE.L        ATLKvars, A3
  415.             BTST        #XTIClose, XTIFlags(A3)            ; see if closing
  416.             BNE.S        @ConnEx
  417.             MOVE.W        #-1, D0
  418.             MOVE.L        D0, -(SP)                        ; the connection result
  419.             MOVE.L        AURPRefNum(A3), -(SP)            ; pass the vars
  420.             MOVE.L        #kAURPTnlConnDone, -(SP)        ; cmdType = TnlConnection Done
  421.             MOVE.L        AURPDispatch(A3), A3             ;
  422.             JSR            (A3)                            ; make the call
  423.             ADDA        #12, SP
  424. @ConnEx        MOVE.L        (SP)+, A3                        ; restore A3
  425.             RTS    
  426.  
  427. ;__________________________________________
  428. ;
  429. ;     GetNextIR 
  430. ;    
  431. ;    Performs the AURP ATnlGetNextIR call.  Returns the
  432. ;    address of the other router.  The next IR reference
  433. ;    indicator is not looked at because this is a point
  434. ;    to point implementation and there is only one
  435. ;    next IR.  If you have used the remoteAddr field, this
  436. ;    code should NOT need to be modified.  May want to tailor
  437. ;    the string based on whether the router is active or
  438. ;    passive on connect.  For example, DialUp, returns "Answering" 
  439. ;    if the router is in answer mode.
  440. ;
  441. ; Call:        D1        =     next ir ref indicator        
  442. ;            A1         ->    next ir string ptr (up to 16 bytes)
  443. ;            
  444. ;            
  445. ; Return:    A1        ->  next IR String
  446. ;            D0.L    =     error code
  447. ;
  448. ;__________________________________________
  449.  
  450. NIRStrMax    EQU            32
  451.  
  452. GetNextIR
  453.             MOVEQ        #0, D0                            ; clear out D0
  454.             MOVE.L        #-1,D3                            ; assume error
  455.             MOVE.L        ATLKvars, A3                    ; get the globals pointer
  456.             BTST.B        #XTIInit, XTIFlags(A3)            ; make sure init'd
  457.             BEQ.S        @GetNxtIRErr                    ; error if not
  458.             CMP.B        #NIRStrMax-1, remoteAddr(A3)    ; see if less than max
  459.             BLS.S        @getStrLen                        
  460.             MOVE.B        #NIRStrMax-1, D0                ; if greater than max, length byte is max - 1
  461.             BRA.S        @copyStr
  462. @getStrLen    MOVE.B        remoteAddr(A3), D0                ; actual length
  463. @copyStr    MOVE.B        D0, (A1)+                        ; length byte
  464.             LEA            remoteAddr+1(A3), A0            ; A0 = ptr to remote addr (src)
  465.  
  466.             _BlockMove                                
  467.             MOVEQ        #0,D3                            ; set result code to no err
  468.             
  469. @GetNxtIRErr
  470.             MOVE.L        D3,D0                            ; move result to D0        
  471.             RTS
  472.             
  473. ;__________________________________________
  474. ;
  475. ;    DoATnlDisconnect 
  476. ;    
  477. ;    Performs the AURP ATnlDisconnect call.  Main code is in C routine
  478. ;    DoXTIDisconnect.  This code should NOT need to be modified.
  479. ;
  480. ; Call:        A3.L    ->    our vars
  481. ;            
  482. ; Return:    D0.L    =     error code
  483. ;
  484. ;__________________________________________
  485.  
  486. DoATnlDisconnect
  487.             MOVE.L        ATLKvars, A3                    ; get the globals pointer
  488.             BSET        #XTIClose, XTIFlags(A3)            ; set flag for closing...
  489.             MOVE.L        A3, -(SP)                        
  490.             JSR            DOXTIDISCONNECT                    ; Call C routine
  491.             ADDQ.L        #4, SP                    
  492.             BCLR        #XTIInit, XTIFlags(A3)            ; no longer inited...
  493.             MOVE.L        D0, -(SP)                        ; the disconnect result
  494.             MOVE.L        AURPRefNum(A3), -(SP)             ; the refnum
  495.             CLR.L        D0
  496.             MOVE.B        #kAURPTnlDiscDone, D0            ; csCode = AURPTnlDiscDone
  497.             MOVE.L        D0, -(SP)
  498.             MOVE.L        AURPDispatch(A3), A0
  499.             JSR            (A0)                            ; make the call
  500.             ADDA        #12, SP
  501.             CLR.L         D0                                ; the disconnect result
  502.             RTS
  503. ;_____________________________________________
  504. ;
  505. ;     DoShutdownAtlk
  506. ;
  507. ;    Performs the AURP AShutdown call.  
  508. ; Call:        D4.B    =    port number on which to perform the shutdown
  509. ;
  510. ; Return:    D0        =    error code
  511. ;
  512. ;_____________________________________________
  513.  
  514. DoShutdownAtlk    
  515.             MOVEQ        #0,D0                            ; no init error has occurred
  516.                                                         ; shut down normally
  517.  
  518. ;_____________________________________________
  519. ;
  520. ;     CloseADEV 
  521. ;    
  522. ;    Complete shutdown.  Also called when an error occurs during
  523. ;    installation or when connecting.  This code should NOT need 
  524. ;    to be modified.
  525. ;            
  526. ; Return:        D0.L    =     error code
  527. ;_____________________________________________
  528.  
  529. CloseADEV
  530.             MOVE.L        D0,D3                            ; save error code
  531.             MOVE.L        ATLKvars,D0                        ; do we have our vars?
  532.             BEQ.S        DoneClose
  533.             
  534.             MOVE.L        D0,A3                            ; A3 -> our vars
  535.             BTST        #XTIInit, XTIFlags(A3)            ; see if we've been inited
  536.             BEQ.S        @SkipClose                        ; if not, skip close of endpoint
  537.             JSR            DoATnlDisconnect
  538.             BRA.S        @ContClose                        ; br to dispose memory
  539.             
  540. @SkipClose
  541.             BSET        #XTIClose, XTIFlags(A3)            ; set flag for closing...
  542. @ContClose
  543.             BSR.S        DeAllocMem
  544.  
  545.             MOVE.W        D3,D0                            ; pass the error code
  546.             RTS
  547.  
  548. DeAllocMem            
  549.             MOVE.L        A3, -(SP)                        
  550.             JSR            DOXTISHUTDOWN                    ; call C routine to dispose memory
  551.             ADDQ.L        #4, SP        
  552.             
  553.             BTST.B        #XTILapInst, XTIFlags(A3)        ; see if LAP write code is installed
  554.             BEQ.S        @NoLAPMgr
  555.             MOVEM.L        D4,-(SP)                        ; save D4
  556.             MOVE.B        OurPortId(A3),D4                ; D4 = our port id    
  557.             MOVE.L        LAPMgrPtr,A1                    ; A1 -> LAP manager
  558.             MOVEQ        #LWrtRemove,D0                    ; function code
  559.             JSR            LAPMgrCall(A1)                    ; call the LAP manager to remove us
  560.             MOVEM.L        (SP)+,D4                        ; restore D4
  561.  
  562. @NoLAPMgr
  563.             MOVE.L        A3,A0                            ; A0 -> our variables
  564.             _DisposPtr                                    ; get rid of them
  565.             MOVE.L        NextIRBlk(A3), A0
  566.             _DisposPtr                                    ; dispose of the NextIRBlk
  567.             LEA            ATLKvars,A0
  568.             CLR.L        (A0)                            ; clear vars ptr
  569.  
  570. DoneClose
  571.             RTS                                            ; That's it (CDEV will dispose us)
  572.             
  573.  
  574.  
  575. ; ___________________________________________
  576. ;
  577. ;     FreeReadBuf
  578. ;
  579. ;     Routine called after route receive completes (ATnlReadDone).  
  580. ;    Set the flag indicating the receive buffer is free, then 
  581. ;    check to see if there are packets waiting to be read.  If 
  582. ;    there are, go read them.  This code should NOT need to be
  583. ;    modified unless the read packet scheme is modified.
  584. ;
  585. ; ___________________________________________
  586.  
  587. FreeReadBuf
  588.             IMPORT        RESTORESR
  589.             
  590.             JSR            RESTORESR                        ; restore interrupt level
  591.             MOVE.L        ATLKvars, A0                    ; A0 -> our vars;
  592.             MOVE.B        #1, rcvBufAvail(A0)                ; set rcvBufAvail boolean
  593.             MOVEQ        #0,D0
  594.             MOVE.B        rcvPktsWaiting(A0), D0
  595.             TST.W        D0                                ; if there are no packets waiting to be read
  596.             BEQ.S        @FreeDone                        ; we are done
  597.             MOVE.L        A0, -(SP)                        ; pass our vars
  598.             JSR         READDONE                        ; call C routine to read packets
  599.             ADDQ.L        #4,SP                            ; restore stack
  600.  
  601. @FreeDone
  602.             RTS
  603.             
  604.             
  605.  
  606. ; ___________________________________________
  607. ;
  608. ;     DoXTIWrite (NIRIndicator dstNextIR, WDSElement *wdsPtr)
  609. ;
  610. ;    Performs the AURP ATnlDoWrite call.  Send the
  611. ;    packet out on the wire.  If an error occurs, call AURPWriteDone
  612. ;    with an error.  Otherwise, it will be called when the T_SendComplete
  613. ;    event is received.  This code should NOT need to be modified.
  614. ;
  615. ; Call:    
  616. ;
  617. ; ___________________________________________
  618.  
  619. DoXTIWrite
  620.  
  621.             MOVE.L        ATLKvars, A3
  622.             MOVE.L        8(SP), wDSPtr(A3)                ; wDSPtr -> send buffer
  623.             MOVE.L        A3, -(SP)                        ; pass our vars
  624.             JSR         XTIWRITE                        ; call C routine to start connection
  625.             ADDQ.L        #4,SP                            ; restore stack
  626.             TST.W        D0
  627.             BNE.S        @WriteErr
  628.             RTS
  629.             
  630. @WriteErr    MOVE.L        D0,-(SP)                        ; the writeResult
  631.             CLR.L        D0
  632.             MOVE.L        ATLKvars,A1
  633.             MOVE.L        wDSPtr(A1), -(SP)                ; the wdsptr
  634.             MOVE.L        XTIVarsRec.AURPRefNum(A1),-(SP)    ; AURP vars
  635.             MOVE.L        #kAURPWriteDone, -(SP)            ; the cmd type
  636.             MOVE.L        XTIVarsRec.AURPDispatch(A1), A0
  637.             JSR            (A0)                            ; call write done with an error
  638.             ADDA        #16, SP
  639.             RTS
  640.                         
  641. ;________________________________________________
  642. ;
  643. ;    GETSYSMEM    (long     sizeNeeded);
  644. ;    
  645. ;    Allocates specified amount of memory in the system heap.
  646. ;    This code should NOT need to be modified.
  647. ;
  648. ;________________________________________________
  649.  
  650. GETSYSMEM    PROC
  651.             MOVE.L        4(A7), D0                        ; get amount to alloc
  652.             _NewPtr        ,SYS,CLEAR                        ; call memory mgr
  653.             BNE.S        @5                                ; error
  654.             MOVE.L        A0, D0                            ; otherwise, get pointer
  655.             BRA.S        @10
  656. @5            CLR.L        D0                                ; if err, D0=0
  657. @10            RTS                                            ; return with pointer in D0
  658.             ENDPROC
  659.             
  660. ;________________________________________________
  661. ;
  662. ;    GETMYA5, SETMYA5
  663. ;
  664. ;    Get and set A5.  Needed to get global variable AtlkVars
  665. ;    from a routine called by the time manager.  This code should 
  666. ;    NOT need to be modified.
  667. ;
  668. ;________________________________________________
  669.  
  670. GETMYA5        PROC
  671.             MOVE.L        A5,D0
  672.             RTS                                            
  673.             ENDPROC
  674.  
  675. SETMYA5        PROC
  676.             MOVE.L        4(A7), A5
  677.             RTS                                            
  678.             ENDPROC
  679.                 
  680. ;________________________________________________
  681. ;
  682. ;    GETSR,   RESTORESR
  683. ;
  684. ;    Set and Restore the interrupt level.  Needed because
  685. ;    the router sets the interrupt level to VSCCEnable 
  686. ;    on completion of a read call.
  687. ;
  688. ;________________________________________________
  689.  
  690.  
  691. GETSR        PROC     EXPORT
  692.             EXPORT    RESTORESR
  693.             LEA        SRX,A0                        ; A0 -> SRX global        
  694.             MOVEQ    #0,D0                        ; clear D0
  695.             MOVE    SR,D0                        ; put the status register into D0
  696.             MOVE.L    D0,(A0)                        ; save the status register
  697.             RTS
  698.             
  699. SRX            DS.L    1
  700.  
  701. RESTORESR    MOVE.L    SRX,D0                        ; saved value into D0
  702.             MOVEQ    #0,D1                        
  703.             MOVE    SR,D1                        ; current status register in D1
  704.             ANDI    #$0700,D1                    ; and with 0x07 to get interrupt level
  705.             ANDI    #$0700,D0                    ; same with D0
  706.             CMP.L    D0,D1                        ; if they aren't the same, 
  707.             BGE.S    @restore                    ; go to restore the status
  708.             RTS
  709.             
  710. @restore    MOVE.L    SRX,D0                        ; saved value in D0
  711.             MOVE    D0,SR                        ; saved value in status register
  712.             RTS
  713.             ENDPROC
  714.                         END
  715.  
  716.